package com.atcd.mq.demo1;


import com.atcd.mq.demo1.rabbitmqUtil.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Scanner;

@SpringBootTest
public class DaoQuene {

    @Test
    public  void test1() throws Exception{
        String QUEUE_NAME = "ask_hello";
        //消息持久化
        Channel channel = RabbitMqUtils.getChannel();
        boolean durable=true;
        channel.queueDeclare(QUEUE_NAME,durable,false,false,null);


        Scanner s = new Scanner(System.in);

        while (s.hasNext()){
            String message = s.next();
            //发布消息 ,加上消息持久化
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes());
            System.out.println(message);
        }



    }
}
